from mindquantum.core.circuit import Circuit
from mindquantum.core.gates import Unitary
import numpy as np

def create_unitary_from_matrix():
    """ Write the function that converts the matrix [[0, 0, 0, 1],[0, 0, 1, 0],[1, 0, 0, 0],[0, 1, 0, 0]] into a unitary gate and apply it to a Quantum Circuit. Then return the circuit.
    """
    matrix = [[0, 0, 0, 1], [0, 0, 1, 0], [1, 0, 0, 0], [0, 1, 0, 0]]
    circuit = Circuit()
    circuit += Unitary(np.array(matrix)).on([0, 1])
    return circuit

def check(candidate):
    from mindquantum.core.circuit import compare_circuits
    matrix = [[0, 0, 0, 1], [0, 0, 1, 0], [1, 0, 0, 0], [0, 1, 0, 0]]
    solution = Circuit()
    solution += Unitary(np.array(matrix)).on([0, 1])
    assert compare_circuits(solution, candidate())

    print("OK")

if __name__ == '__main__':
    check(create_unitary_from_matrix)